@using BlazorApp.Pages.Common
@using BlazorApp.Pages.Common.Html
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using Extension
@using k8s.Models
@inherits BlazorApp.Pages.Common.DrawerPageBase<V1PodSecurityContext>
@if (SecurityContext != null && !SecurityContext.ToJson().Equals("{}"))
{
    <Divider Orientation="left" Style="font-weight:bold"> @L["ContainerSecurityContext"]</Divider>

    <HTable Bordered Column="1">
        <PropertySimpleView Title=@L["RunAsGroup"] Item="@SecurityContext.RunAsGroup"
                            ExplainField="pod.spec.containers.securityContext.runAsGroup">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["RunAsNonRoot"] Item="@SecurityContext.RunAsNonRoot"
                            ExplainField="pod.spec.containers.securityContext.runAsNonRoot">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["RunAsUser"] Item="@SecurityContext.RunAsUser"
                            ExplainField="pod.spec.containers.securityContext.runAsUser">
        </PropertySimpleView>
        @if (SecurityContext.SeLinuxOptions != null)
        {
            <HTableColumn Title=@L["SeLinuxOptions"] ExplainField="pod.spec.containers.securityContext.seLinuxOptions">

                @if (SecurityContext.SeLinuxOptions.Level != null)
                {
                    <ColorfulTag>
                        @($"Level={SecurityContext.SeLinuxOptions.Level}")
                    </ColorfulTag>
                }
                @if (SecurityContext.SeLinuxOptions.User != null)
                {
                    <ColorfulTag>
                        @($"User={SecurityContext.SeLinuxOptions.User}")
                    </ColorfulTag>
                }
                @if (SecurityContext.SeLinuxOptions.Type != null)
                {
                    <ColorfulTag>
                        @($"Type={SecurityContext.SeLinuxOptions.Type}")
                    </ColorfulTag>
                }
                @if (SecurityContext.SeLinuxOptions.Role != null)
                {
                    <ColorfulTag>
                        @($"Role={SecurityContext.SeLinuxOptions.Role}")
                    </ColorfulTag>
                }
            </HTableColumn>
        }

        @if (SecurityContext.SeccompProfile != null)
        {
            <PropertyOptionView Title=@L["SeccompProfile"] ExplainField="pod.spec.containers.securityContext.seccompProfile"
                                Item="@SecurityContext.SeccompProfile.Type"
                                Options='@(new[] { "Localhost", "RuntimeDefault", "Unconfined" })'>
            </PropertyOptionView>
            <PropertySimpleView Title=@L["LocalhostProfile"]
                                ExplainField="pod.spec.containers.securityContext.seccompProfile.LocalhostProfile"
                                Item="@SecurityContext.SeccompProfile.LocalhostProfile">
            </PropertySimpleView>
        }

        <PropertySimpleView Title=@L["AllowPrivilegeEscalation"] Item="@SecurityContext.AllowPrivilegeEscalation"
                            ExplainField="pod.spec.containers.securityContext.allowPrivilegeEscalation">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["Privileged"] Item="@SecurityContext.Privileged"
                            ExplainField="pod.spec.containers.securityContext.privileged">
        </PropertySimpleView>
        <PropertyOptionView Title=@L["ProcMount"] ExplainField="pod.spec.containers.securityContext.procMount"
                            Item="@SecurityContext.ProcMount"
                            Options='@(new[] { "Default", "Unmasked" })'>
        </PropertyOptionView>
        <PropertySimpleView Title=@L["ReadOnlyRootFilesystem"] Item="@SecurityContext.ReadOnlyRootFilesystem"
                            ExplainField="pod.spec.containers.securityContext.readOnlyRootFilesystem">
        </PropertySimpleView>
        @if (SecurityContext.Capabilities != null)
        {
            <HTableColumn Title=@L["Capabilities"] ExplainField="pod.spec.containers.securityContext.capabilities">

                @if (SecurityContext.Capabilities.Add is { Count: > 0 })
                {
                    <Alert Type="@AlertType.Success">
                        Add:
                        @foreach (var a in SecurityContext.Capabilities.Add)
                        {
                            <ColorfulTag>@a</ColorfulTag>
                        }
                    </Alert>
                }
                @if (SecurityContext.Capabilities.Drop is { Count: > 0 })
                {
                    <Alert Type="@AlertType.Error">
                        Drop:
                        @foreach (var a in SecurityContext.Capabilities.Drop)
                        {
                            <ColorfulTag>@a</ColorfulTag>
                        }
                    </Alert>
                }
            </HTableColumn>
        }
        @if (SecurityContext.WindowsOptions != null)
        {
            <HTableColumn Title=@L["WindowsOptions"] ExplainField="pod.spec.securityContext.windowsOptions">

                @if (SecurityContext.WindowsOptions.GmsaCredentialSpec != null)
                {
                    <div>


                        <ColorfulTag>
                            @($"GmsaCredentialSpec={SecurityContext.WindowsOptions.GmsaCredentialSpec}")
                        </ColorfulTag>
                    </div>
                }
                @if (SecurityContext.WindowsOptions.GmsaCredentialSpecName != null)
                {
                    <div>
                        <ColorfulTag>
                            @($"GmsaCredentialSpecName={SecurityContext.WindowsOptions.GmsaCredentialSpecName}")
                        </ColorfulTag>
                    </div>
                }
                @if (SecurityContext.WindowsOptions.HostProcess != null)
                {
                    <div>
                        <ColorfulTag>
                            @($"HostProcess={SecurityContext.WindowsOptions.HostProcess}")
                        </ColorfulTag>
                    </div>
                }
                @if (SecurityContext.WindowsOptions.RunAsUserName != null)
                {
                    <div>
                        <ColorfulTag>
                            @($"RunAsUserName={SecurityContext.WindowsOptions.RunAsUserName}")
                        </ColorfulTag>
                    </div>
                }
            </HTableColumn>
        }

    </HTable>
}

@code{

    [Parameter] public V1SecurityContext SecurityContext { get; set; }

}
